package backend.component;

import midend.IR_Value.IR_FuncBlock;

import java.util.ArrayList;

public class RISCVmodule {
    private ArrayList<RISCVfunction> functions;
    private ArrayList<RISCVglobalvar> globalVariables;

    public RISCVmodule() {
        this.globalVariables = new ArrayList<>();
        this.functions = new ArrayList<>();
    }

    public ArrayList<RISCVfunction> getFunctions() {
        return functions;
    }

    public ArrayList<RISCVglobalvar> getGlobalVariables() {
        return globalVariables;
    }

    public void addGlobalVariable(RISCVglobalvar objGlobalVariable) {
        globalVariables.add(objGlobalVariable);
    }

    public void addFunction(RISCVfunction objFunction) {
        functions.add(objFunction);
    }

    public RISCVfunction getObjFunction(IR_FuncBlock irFunction) {
        for (RISCVfunction objF : functions) {
            if (objF.isThis(irFunction.get_FuncName())) {
                return objF;
            }
        }
        return null;
    }

    public ArrayList<RISCVfunction> functions() {
        return functions;
    }

    public void setFunctions(ArrayList<RISCVfunction> functions) {
        this.functions = functions;
    }

    public ArrayList<RISCVglobalvar> globalVariables() {
        return globalVariables;
    }

    public void setGlobalVariables(ArrayList<RISCVglobalvar> globalVariables) {
        this.globalVariables = globalVariables;
    }
}
